home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-02 / tool-inc.zip / POP2.INC < prev    next >
Text File  |  1989-03-01  |  5KB  |  234 lines

  1.  
  2. (*
  3.  * Copyright 1987, 1989 Samuel H. Smith;  All rights reserved
  4.  *
  5.  * This is a component of the ProDoor System.
  6.  * Do not distribute modified versions without my permission.
  7.  * Do not remove or alter this notice or any other copyright notice.
  8.  * If you use this in your own program you must distribute source code.
  9.  * Do not use any of this in a commercial product.
  10.  *
  11.  *)
  12.  
  13. (*
  14.  * popup - utility library for simple "pop-up" windows (3-1-89)
  15.  *
  16.  *)
  17.  
  18. var
  19.   Vmode:       byte    absolute $0040:$0049;   {Current video mode}
  20.  
  21. {video modes}
  22. const
  23.   NoDisplay = $00;   VgaMono   = $07;
  24.   MdaMono   = $01;   VgaColor  = $08;
  25.   CgaColor  = $02;   DCC9      = $09;
  26.   DCC3      = $03;   DCC10     = $0A;
  27.   EgaColor  = $04;   McgaMono  = $0B;
  28.   EgaMono   = $05;   McgaColor = $0C;
  29.   PgcColor  = $06;   Unknown   = $FF;
  30.  
  31. const
  32.    low_attr:  integer = 7;
  33.    norm_attr: integer = 15;
  34.    back_attr: integer = 0;
  35.  
  36. type
  37.    popup_string = string[255];
  38.  
  39.    screenloc =         record
  40.          character:          char;
  41.          attribute:          byte;
  42.    end;
  43.  
  44.    videoram =          array [0..1999] of screenloc;
  45.    videoptr =          ^videoram;
  46.  
  47.    window_rec = record
  48.       x1,y1,x2,y2: integer;
  49.       attr:        byte;
  50.    end;
  51.  
  52.    window_save_rec = record
  53.       win:      window_rec;
  54.       scr:      videoram;
  55.       cux,cuy:  integer;
  56.    end;
  57.  
  58.  
  59. var
  60.    cur_window:   window_rec;
  61.    saved_window: window_save_rec;
  62.    disp_mem:     videoptr;
  63.  
  64.  
  65. procedure setcolor(fg,bg: integer);
  66. begin
  67.    bg := bg and 7;
  68.    textcolor(fg);
  69.    textbackground(bg);
  70.    cur_window.attr := fg + bg shl 4;
  71. end;
  72.  
  73. procedure normvideo;
  74. begin
  75.    setcolor(norm_attr,back_attr);
  76. end;
  77.  
  78. procedure lowvideo;
  79. begin
  80.    setcolor(low_attr,back_attr);
  81. end;
  82.  
  83. procedure old_window(win: window_rec);   {redefine the old window
  84.                                           command so it can still be
  85.                                           used by other procs}
  86. begin
  87.    with win do
  88.       window(x1,y1,x2,y2);
  89. end;
  90.  
  91. procedure window(a1,b1,a2,b2: integer);    {make a new version of window
  92.                                             that saves the current state}
  93. begin
  94.    with cur_window do
  95.    begin
  96.       x1 := a1;
  97.       y1 := b1;
  98.       x2 := a2;
  99.       y2 := b2;
  100.    end;
  101.  
  102.    old_window(cur_window);
  103. end;
  104.  
  105.  
  106.  
  107. function make_string(c: char; len: integer): popup_string;
  108.    {make a string by repeating a character n times}
  109. var
  110.    i:  integer;
  111.    s:  popup_string;
  112. begin
  113.    for i := 1 to len do
  114.       s[i] := c;
  115.  
  116.    s[0] := chr(len);
  117.    make_string := s;
  118. end;
  119.  
  120.  
  121. procedure disp (s:                  popup_string);
  122.    {very fast dma string display}
  123. var
  124.    index:              integer;
  125.    i:                  integer;
  126.    c:                  char;
  127.    len:                integer;
  128.    max_index:          integer;
  129.  
  130. begin
  131.  
  132.    with cur_window do
  133.    begin
  134.       len := ord(s[0]);
  135.       index :=(wherey + y1 - 2)* 80 +(wherex + x1 - 2);
  136.       max_index := y2*80;
  137.  
  138.       for i := 1 to len do
  139.       begin
  140.          c := s [i];
  141.  
  142.          case c of
  143.             ^H:   dec(index);
  144.  
  145.             ^J:   begin
  146.                      index := index + 80;
  147.                      if index >= max_index then
  148.                      begin
  149.                         write(^J);
  150.                         index := index - 80;
  151.                      end;
  152.                   end;
  153.  
  154.             ^M:   index :=(index div 80)* 80 + x1 - 1;
  155.  
  156.             ^G:   write(^G);
  157.  
  158.             else  begin
  159.                      with disp_mem^[index] do
  160.                      begin
  161.                         character := c;
  162.                         attribute := attr;
  163.                      end;
  164.  
  165.                      inc(index);
  166.  
  167.                      if index >= max_index then
  168.                      begin
  169.                         index := index - 80;
  170.                         writeln;
  171.                      end;
  172.                   end;
  173.          end;
  174.       end;
  175.  
  176. (* place cursor at end of displayed string *)
  177.       gotoxy((index mod 80)- x1 + 2,(index div 80)- y1 + 2);
  178.    end;
  179. end;
  180.  
  181.  
  182.  
  183. procedure displn(s: popup_string);       {fast display and linefeed}
  184. begin
  185.    disp(s);
  186.    writeln;
  187. end;
  188.  
  189.  
  190. procedure save_window(var saved: window_save_rec);
  191.    (* save the current window so it can be restored later *)
  192. begin
  193.    saved.scr := disp_mem^;
  194.    saved.win := cur_window;
  195.    saved.cux := wherex;
  196.    saved.cuy := wherey;
  197. end;
  198.  
  199.  
  200. procedure restore_window(saved: window_save_rec);
  201.    (* restore the windowing settings *)
  202. begin
  203.    cur_window := saved.win;
  204.    old_window(cur_window);
  205.  
  206. (* restore the cursor position *)
  207.    gotoxy(saved.cux,saved.cuy);
  208.  
  209. (* restore the display contents *)
  210.    disp_mem^ := saved.scr;
  211.  
  212. (* restore current video mode *)
  213.    if cur_window.attr = low_attr then
  214.       lowvideo
  215.    else
  216.       normvideo;
  217. end;
  218.  
  219.  
  220. procedure init_pop_up;
  221.    {call once before anything else in this library}
  222. begin
  223.    case Vmode of
  224.       MdaMono, VgaMono:
  225.          disp_mem := ptr($B000,0);
  226.       else
  227.          disp_mem := ptr($B800,0);
  228.    end;
  229.  
  230.    window(1,1,80,25);
  231.    normvideo;
  232. end;
  233.  
  234.